<!DOCTYPE html>
<!-- saved from url=(0032)http://my.sto.cn/Vip/UserManager -->
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit|ie-comp|ie-stand">


    <script type="text/javascript" src="/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.data.js"></script>
    <script type="text/javascript" src="/home/js/city-picker.js"></script>
    <script type="text/javascript" src="/home/js/layer.js"></script>
    <link rel="stylesheet" type="text/css" href="/home/userManager/css/common.css">
    <link rel="stylesheet" type="text/css" href="/home/branch/css/city-picker.css">
    <link rel="stylesheet" type="text/css" href="/home/userManager/css/combo.select.css">
    <link rel="stylesheet" type="text/css" href="/home/userManager/css/userInfo.css">
    <link rel="stylesheet" type="text/css" href="/home/layui/css/layui.css">

<body>
<#setting datetime_format="yyyy-MM-dd"/>
<#include "../common/header.ftl">
<#include "../common/top_nav.ftl">
<div class="box" style="min-height:800px;">
    <div class="viewAddress">
        <div class="left">
            <div class="title">
                <span><img src="/home/userManager/images/user.png" alt="账户icon"></span>
                <span class="titleText">账户管理</span>
            </div>
            <ul>
                <li><a class="<#if active == 0>on</#if>" href="/home/userManager/index">基本信息</a></li>
                <li><a class="<#if active == 1>on</#if>" href="/home/address/list">地址中心</a></li>
                <li><a class="<#if active == 2>on</#if>" href="/home/userManager/realName">实名认证</a></li>
            </ul>
        </div>
        <div class="right">
            <div class="title">
                <div class="titleBox">
                    <span class="txt">个人信息</span>
                    <span class="icon"><a href="javascript:void(0)">
                            <img src="/home/userManager/images/edit.png" alt="编辑"></a>
                        </span>
                    <span class="edit"> <a href="javascript:void(0)" id="saveUser">保存</a>
                            <a onclick="hide(this)" class="cut" href="javascript:void(0)">取消</a></span>
                </div>
            </div>
            <div class="viewUserInfo" style="margin-top: 50px;margin-bottom: 60px">
                <form id="updateForm" method="post">
                    <div class="userInfoBox">
                        <div class="line">
                            <div class="l_left">
                                <label>姓名：</label>
                                <input type="text" class="userText" id="name" name="name"
                                       value="${homeUser.name!""}">
                            </div>
                            <div class="l_right">
                                <label>生日：</label>
                                <input id="birthday" type="text" name="birthday"
                                       value="<#if homeUser.birthday??>${homeUser.birthday?string("yyyy-MM-dd")!""}</#if>"
                                       class="userText" autocomplete="off" readonly>
                            </div>
                            <div class="clear"></div>
                        </div>
                        <div class="line">
                            <div class="l_left">
                                <label>手机：</label>
                                <input type="text" id="mobile" name="mobile" class="userText"
                                       value="${homeUser.mobile!""}">
                            </div>
                            <div class="l_right">
                                <label>性别：</label>
                                <select id="sex" name="sex" tabindex="-1">
                                        <#if homeUser.sex??>
                                            <#if homeUser.sex == 2>
                                                <option>女</option>
                                                <option>男</option>
                                            <#else >
                                                <option>男</option>
                                                <option>女</option>
                                            </#if>
                                        <#else >
                                            <option>男</option>
                                            <option>女</option>
                                        </#if>
                                </select>
                            </div>
                            <div class="clear"></div>
                        </div>
                        <div class="line">
                            <div class="l_left">
                                <label>省市区：</label>
                                <input id="address" name="address" value="${homeUser.address!""}"
                                       class="userText addressChoose city-picker-input"
                                       type="text" data-toggle="city-picker" readonly>
                            </div>
                            <div class="l_right">
                                <label>详细地址：</label>
                                <input type="text" id="detailedAddress" name="detailedAddress" class="userText"
                                       value="${homeUser.detailedAddress!""}">
                            </div>
                            <div class="clear"></div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="verifyInfo">
                <div class="space">
                    <div>密码设置</div>
                </div>
                <div class="vContent">
                    <p>
                        <span> 登陆后修改您的账号密码</span> <a href="/home/userManager/updatePassword">修改&gt;&gt;</a>
                    </p>
                </div>
            </div>
        </div>
    </div>

</div>
    <#include "../common/footer.ftl"/>


<script type="text/javascript" src="/home/js/msg.js"></script>
<script type="text/javascript" src="/home/layui/layui.all.js"></script>

<script type="text/javascript" src="/home/userManager/js/jquery.combo.select.js"></script>
<script>



    $(document).ready(function () {

        layui.use('laydate', function () {
            var laydate = layui.laydate;
            laydate.render({
                elem: '#birthday',
                type: 'date',
                format: 'yyyy-MM-dd'
            });
        });



        //点击保存按钮
        $("#saveUser").click(function () {
            var id = $("#homeUserId").val();
            var name = $("#name").val();
            var birthday = $("#birthday").val();
            var mobile = $("#mobile").val();
            var sex = $("#sex").val() == "男" ? 1 : 2;
            var address = $("#address").val();
            var detailedAddress = $("#detailedAddress").val();
            if (!name) {
                errorMsg("姓名不能为空");
                return;
            }
            if (!/(^[\u4E00-\u9FA5]+$)|(^[\u4E00-\u9FA5]*·[\u4E00-\u9FA5]*$)/.test($("#name").val())) {
                errorMsg("姓名格式不正确");
                return false;
            }
            if (!birthday) {
                errorMsg("生日不能为空");
                return;
            }
            if (!mobile) {
                errorMsg("手机号码不能为空");
                return;
            }
            if (mobile.length > 11) {
                errorMsg("手机号码格式不正确");
                return;
            }
            if (!mobile.match(/^1(3|4|5|6|7|8|9)\d{9}$/)) {
                errorMsg("请输入有效的手机号码");
                return;
            }
            if (!address) {
                errorMsg("省市区不能为空");
                return;
            }
            if ($("#address").val().split('/').length != 3){
                errorMsg("请选择完整的省市区");
                return;
            }
            if (!detailedAddress) {
                errorMsg("请填写详细地址");
                return;
            }
            var homeUser = {};
            homeUser.id = id;
            homeUser.name = name;
            homeUser.birthday = birthday;
            homeUser.mobile = mobile;
            homeUser.sex = sex;
            homeUser.address = address;
            homeUser.detailedAddress = detailedAddress;
            $.ajax({
                type: "post",
                dataType: "json",
                url: "/home/userManager/update",
                data: homeUser,
                success: function (data) {
                    if (data.code == 0) {
                        successMsg("修改成功");
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);
                    } else {
                        errorMsg(data.msg);
                    }
                }
            });
        });

    });


    $(function () {
        $('select').comboSelect();   // 下拉框插件 启动
    });


    $(function () {
        $(".icon").find("a").click(function () {
            $(".edit").show();
            $(".icon").hide();
        })
    });

    function hide() {
        $(".edit").hide();
        $(".icon").show();
    }
</script>
</body>
</html>